//
//	 ______    ______    ______    
//	/\  __ \  /\  ___\  /\  ___\   
//	\ \  __<  \ \  __\_ \ \  __\_ 
//	 \ \_____\ \ \_____\ \ \_____\ 
//	  \/_____/  \/_____/  \/_____/ 
//
//	Powered by BeeFramework
//
//
//  Board_iPhone_UpdatePassWord.m
//  DingDing
//
//  Created by LHL on 14/11/22.
//  Copyright (c) 2014年 com.gordon. All rights reserved.
//

#import "Board_iPhone_UpdatePassWord.h"

#pragma mark -

@interface Board_iPhone_UpdatePassWord()
{
	//<#@private var#>
}
@end

@implementation Board_iPhone_UpdatePassWord

SUPPORT_AUTOMATIC_LAYOUT( YES )
SUPPORT_RESOURCE_LOADING( YES )
DEF_OUTLET(BeeUIButton, confirm)
DEF_OUTLET(BeeUITextField, newpasswd)
DEF_OUTLET(BeeUITextField, oldpasswd)
DEF_OUTLET(BeeUITextField, reviewPwd)
DEF_MODEL(changePassword, ichangePassword)
- (void)load
{
    self.ichangePassword = [changePassword modelWithObserver:self];
}

- (void)unload
{
}

#pragma mark - Signal

ON_CREATE_VIEWS( signal )
{
    self.navigationBarShown = YES;
    self.navigationBarLeft = [UIImage imageNamed:@"back.png"];
}

ON_SIGNAL3(changePassword, RELOADED, SIGNAL){
    [self dismissTips];
    if ([self.ichangePassword.code isEqualToString:@"200"]) {
        [self presentMessageTips:@"修改成功"];
        [self performSelector:@selector(popFunc) withObject:nil afterDelay:1.0];
    }else{
        [self presentMessageTips:self.ichangePassword.msg];
    }
}
-(void)popFunc{
    [self.navigationController popViewControllerAnimated:YES];
}

ON_SIGNAL3(changePassword, RELOADING, SIGNAL){
    [self presentLoadingTips:@"加载中"];
}

ON_SIGNAL3(changePassword, FAILED, SIGNAL){
    [self dismissTips];
    [self presentMessageTips:self.ichangePassword.msg];
}

ON_SIGNAL3(BeeUIButton, confirm, signal){
    if (self.oldpasswd.text.length ==0) {
        [self presentMessageTips:@"旧密码不能为空"];
        return;
    }
    if (self.newpasswd.text.length == 0) {
        [self presentMessageTips:@"新密码不能为空"];
        return;
    }
    if (self.newpasswd.text.length < 6) {
        [self presentMessageTips:@"新密码长度不能小于6位"];
        return;
    }
    
    if (self.reviewPwd.text.length == 0) {
        [self presentMessageTips:@"重复密码不能为空"];
        return;
    }
    if (self.reviewPwd.text.length < 6) {
        [self presentMessageTips:@"重复密码长度不能小于6位"];
        return;
    }
    if (![self.reviewPwd.text isEqualToString:self.newpasswd.text]) {
        [self presentMessageTips:@"新密码与重复密码不匹配"];
        return;
    }
    self.ichangePassword.newpassword = self.newpasswd.text;
    self.ichangePassword.oldpassword = self.oldpasswd.text;
    [self.ichangePassword firstPage];
}

ON_DELETE_VIEWS( signal )
{
}

ON_LAYOUT_VIEWS( signal )
{
}

ON_WILL_APPEAR( signal )
{
}

ON_DID_APPEAR( signal )
{
}

ON_WILL_DISAPPEAR( signal )
{
}

ON_DID_DISAPPEAR( signal )
{
}

ON_SIGNAL3( BeeUINavigationBar, LEFT_TOUCHED, signal )
{
    [self.navigationController popViewControllerAnimated:YES];
}

ON_SIGNAL3( BeeUINavigationBar, RIGHT_TOUCHED, signal )
{
}

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
    [self resign];
}

-(void)resign{
    for (UIView *t in self.view.subviews) {
        if ([t isKindOfClass:[BeeUITextField class]]) {
            [t resignFirstResponder];
        }
    }
}

@end
